﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using EraNet.Core.Model.Test;
using EraNet.Services.SysManage;
using EraNet.Core.Model.Account;
using EraNet.Services.Account;
using EraNet.Common;
using EraNet.Core.Model.SysManage;
using EraNet.WebApp.AppCore;
namespace EraNet.WebApp.LMS
{
    public class CommonController : LMSBasePage
    {

        #region Fields
        private readonly IMemberService _memberService;
        private readonly ISysCardsService _syscardService;
        #endregion

        #region Constructors
        public CommonController(IMemberService memberService, ISysCardsService syscardService)
        {
            this._memberService = memberService;
            this._syscardService = syscardService;
        }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult _LeftInfo()
        {
            return View();
        }

        public ActionResult _Menu()
        {
            return View();
        }

        public ActionResult _TopNav()
        {
            Member m = _memberService.GetLoginMember();
            return View(m);
        }

        public JsonResult setPassword(string oldPwd, string newPwd, string ConfigNewPwd)
        {
            #region 为空校验
            //身份证号不能为空
            if (string.IsNullOrEmpty(oldPwd))
                return Json("1", JsonRequestBehavior.AllowGet);
            if (string.IsNullOrEmpty(newPwd))
                return Json("2", JsonRequestBehavior.AllowGet);
            if (string.IsNullOrEmpty(ConfigNewPwd))
                return Json("3", JsonRequestBehavior.AllowGet);
            #endregion

            Member m = _memberService.GetLoginMember();

            m = _memberService.GetMemberById(m.Id);

            if (newPwd != ConfigNewPwd)
            {
                return Json("5", JsonRequestBehavior.AllowGet);
            }


            string msg = string.Empty;

            if (m.Password != Utility.MD5(oldPwd))
            {
                return Json("4", JsonRequestBehavior.AllowGet);
            }
            m.Password = Utility.MD5(newPwd);
            if (_memberService.UpdateMember(m) > 0)
            {
                msg = "6";
            }
            else
                msg = "7";

            return Json(msg, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 注销登录
        /// </summary>
        /// <returns></returns>
        public ActionResult LogOffMember()
        {
            EraNet.Common.Utility.WriteCookie("MemberModel","");
            EraNet.Common.Utility.WriteCookie("CardModel", "");

            return RedirectToAction("Index", "Account");
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult _Notify()
        {
            return View();
        }

        public ActionResult _Submit()
        {
            return View();
        }
    }
}
